<?php
/*
 * @Author: your name
 * @Date: 2019-12-19 15:33:29
 * @LastEditTime: 2020-12-28 09:55:58
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ahsmp_3/application/common/service/ServerSocketMessageHistory.php
 */

namespace app\common\service\platform_manage\log;


use app\common\service\BaseService;
use think\Db;

class ServerSocketMessageHistoryService extends BaseService
{

    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-20 09:58:47
     */
    public function list ($userId, $isRoot = false)
    {
        $return = Db::name('ServerSocketMessageHistory')
            ->field('id,host_id,module,user_id,description,content_md5,err_id,err_msg,ctime,callback_status')
            //查询条件： 下发失败或者下发成功，但是尚未回调的数据
            ->where(function ($query){
                $query->where('err_id', '>',0)
                    ->whereOr(function ($query){
                        $query->where('err_id', '=',0)->where('callback_status','=',0);
                    });
            })
            ->where('ignore', 0);

        //非超级管理员角色,根据用户角色查询数据
        if(!$isRoot){
            $return = $return->where('user_id', 'in',$userId);
        }
        $return = $return->order('ctime desc')->paginate()->toArray();
        return $return;
    }

    /**
     * @name: 错误条数
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:09:20
     */
    public function errCount($userId)
    {
        return Db::name('ServerSocketMessageHistory')->where('user_id', $userId)->where('err_id', '>', 0)->where('ignore', 0)->count();
    }

    /**
     * @name: 忽略
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-01-03 14:25:47
     */
    public function ignore ($id_s)
    {
        return Db::name('ServerSocketMessageHistory')->whereIn('id', $id_s)->update(['ignore' => 1]);
    }
}